# -*- conding:UTF-8 -*-

'''
@ Project: P8 flask_progect
@ File: vip.py
@ Author: 罗婷
@ Date：2022/6/28 15:50

'''
import json
from flask import Blueprint, jsonify
from flask_restful import Api, Resource, reqparse, marshal
from common.jwt.check_token import token_check
from common.model_fields.courses import *
from common.model_fields.users import users_fields, vip_fields
from common.models.users import *

vip_bp = Blueprint('vip_bp', __name__,url_prefix='/vip')

api = Api(vip_bp)

# 会员页面展示---请求会员列表
class VipList(Resource):
    def get(self):
        vips = VipModel.query.all()
        vipSet = {}
        for i in vips:
            if i.level == 0:  # 普通用户
                vip_data = json.loads(json.dumps(marshal(i, vip_fields)))
                vipSet['common_user_list'] = vip_data
            if i.level == 1:  # 普通会员
                vip_data = json.loads(json.dumps(marshal(i, vip_fields)))
                vipSet['common_vip_list'] = vip_data
            if i.level == 2:  # 高级会员
                vip_data = json.loads(json.dumps(marshal(i, vip_fields)))
                vipSet['expert_vip_list'] = vip_data
        return jsonify(message='会员列表信息获取成功', code=200, data=vipSet)



# 请求会员列表
api.add_resource(VipList, '/get_vip_list')




















